<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Young粉信息</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="applicable-device" content="mobile">
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=yes, width=device-width">
	<meta name="format-detection" content="telephone=no" />
    <link rel="stylesheet" href="css/ui-selectbox.css">
	<link rel="stylesheet" href="css/style.css">
	<script src="js/jquery.js"></script>
    <script src="js/common.js"></script>
    <script src="js/selectbox-min.js"></script>
	<script type="text/javascript">
	$(document).ready(function(){
			$.ajax({
				type: "post",
			 	url: "/personalcenter/useredit",
			    dataType: "json",
				success: function (data) {
			    	if(data.result==0){
			    		var year=new Date().getFullYear(); 
			    		$("#userimg").attr('src',data.headimg);
			    		$("#userpoints").html(data.points);
			    		$("#userchange").html(data.changecounts);
			    		$("#usermobile").html(data.mobile.replace(/(\d{3})\d{6}(\d{2})/,'$1******$2'));
			    		$("#usermobile").val(data.mobile);
			    		$("#sel-school").html("<option value='"+data.school+"' selected='selected'>"+data.school+"</option>"+data.schoollist);
			    		$("#sel-building").html("<option value='"+data.building+"' selected='selected'>"+data.building+"</option>"+data.buildinglist);
			    		$("#sel-year").html("<option value='"+data.grade+"' selected='selected'>"+data.grade+"年</option><option value='"+year+"'>"+year+"</option><option value='"+(year-1)+"'>"+(year-1)+"</option><option value='"+(year-2)+"'>"+(year-2)+"</option><option value='"+(year-3)+"'>"+(year-3)+"</option><option value='"+(year-4)+"'>"+(year-4)+"</option><option value='"+(year-5)+"'>"+(year-5)+"</option><option value='"+(year-6)+"'>"+(year-6)+"</option><option value='"+(year-7)+"'>"+(year-7)+"</option>");
			    		$("#username").val(data.name);
			    		$("#usermajor").val(data.major);
			    		$('select').each(function () {
			    	        selectbox(this);
			    	    }); 
			    	}else{
			    		window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe643cc1b34aa8f25&redirect_uri=http%3a%2f%2fa6.189young.com%2fpersonalcenter%2fcheckuser&response_type=code&scope=snsapi_base&state=1#wechat_redirect';
			    	}
			    }
			}); 
	 	});
	
	   function changeSchool(){
		   $.ajax({
				type: "post",
			 	url: "/personalcenter/signupschool",
			 	data: {school:$.trim($("#sel-school").val())},
			    dataType: "json",
				success: function (data) {
			    	if(data.result==0){
			    		$("#sel-building").html(data.school);
			    		$('select').each(function () {
			    	        selectbox(this);
			    	    });
			    	}else{
			    		window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe643cc1b34aa8f25&redirect_uri=http%3a%2f%2fa6.189young.com%2fpersonalcenter%2fcheckuser&response_type=code&scope=snsapi_base&state=1#wechat_redirect';
			    	}
			    }
			}); 
	   }
	</script>
</head>
<body>
    <div class="page">

        <header class="user-header">
          <a href="javascript:history.go(-1);" class="btn-back posa">返回</a>
          <div class="img-box user-photo"><img src="img/icon_index_menu07.png" alt="" id="userimg"></div>
          <div class="tc user-header-info">
            <a href="user_point.html" class="user-header-info-link"><b id="userpoints"></b><span>我的积分</span></a>
            <a href="user_goods.html" class="user-header-info-link"><b id="userchange"></b><span>我的兑换</span></a>
          </div>
        </header>
        
        <div class="edit-form">
          <div class="edit-row clearfix edit-phone">
            <div class="fl edit-label">手机号码：</div>
            <div class="fr edit-right"><div class="edit-placeholder" id="usermobile"></div></div>
          </div>

          <div class="edit-row clearfix">
            <div class="fl edit-label">学校校区：</div>
            <div class="fr edit-right">
              <select id="sel-school" onchange="changeSchool()">
              
              </select>
            </div>
            
          </div>
          <div class="edit-row clearfix">
            <div class="fl edit-label">楼：</div>
            <div class="fr edit-right">
              <select id="sel-building">
              
              </select>
            </div>
            
          </div>
          <div class="edit-row clearfix">
            <div class="fl edit-label">入学年份：</div>
            <div class="fr edit-right">
              <select id="sel-year">
              
              </select>
            </div>
            
          </div>
          <div class="edit-row clearfix">
            <div class="fl edit-label">姓名：</div>
            <div class="fr edit-right"><input type="text" placeholder="请输入您的姓名" value="" id="username"></div>
            
          </div>
          <div class="edit-row clearfix">
            <div class="fl edit-label">专业：</div>
            <div class="fr edit-right"><input type="text" placeholder="请输入您的专业" value="" id="usermajor"></div>
            
          </div>

          <div class="form-ps">小Young提醒：<br>为保证服务的质量及正确，请保证个人信息正确哦，校区和楼将影响宽带相关服务，如果搬迁请及时更新。</div>
          

          <div class="tc btn-bottom"><button onclick="commit()" class="btn btn-login">确认提交</button></div>
        </div>

        <div class="out-mask"></div>
        <!-- 注册成功弹窗 -->
        <div class="out-box out-changePhone">
          <div class="out-box-inner">
            <div class="login-raw"><input type="tel" placeholder="请输入您的手机号码（必填）" id="changemobile"></div>
            <div class="login-raw clearfix"><input type="text" class="fl txt-yzm" placeholder="请输入图形验证码" id="lockcode"><img onclick="getlockcode()" id="lockimg" class="fr btn-yzm" src="/personalcenter/lockcode"></img></div>
            <div class="login-raw clearfix"><input type="tel" class="fl txt-yzm" placeholder="请输入短信验证码" id="usercode"><button onclick="getcode()" id="button" class="fr btn-yzm">获得短信码</button></div>
            <div class="tc out-btn-row"><a href="javascript:changeMobile();" class="btn btn-yellow">确认修改</a></div>
          </div>
        </div>
        
    </div>

    <script>
      $(function(){
        // 修改手机号码弹窗出现
        $('.edit-phone').on('click',function(){
          boxIn($('.out-changePhone'));
        })

       /*  // 确认修改关闭弹窗
        $('.out-changePhone .out-btn-row .btn').on('click',function(){
          boxOut($('.out-changePhone'));
        }) */
        

      })
      
      function getlockcode(){
    	  $("#lockimg").attr("src","/personalcenter/lockcode");
      }
      
      function getcode(){
	  if($.trim($("#changemobile").val()) == ""){
	        alert("手机号码不能为空！");
	        return false;
	    }
	    if (!$("#changemobile").val().match(/^1[3,4,5,6,7,8,9]\d{9}$/)) { 
	        alert("请正确填写手机号码！");
	        return false;
	    }
	    if($.trim($("#lockcode").val()) == ""){
	        alert("图形验证码不能为空！");
	        return false;
	    }
	    //向后台发送处理数据
		//短信验证
		wait();
		$.ajax({ 
	      type: "post", 
	      url: "/personalcenter/message", 
	      data: {mobile:$.trim($("#changemobile").val()),lockcode:$.trim($("#lockcode").val())},
	      dataType: "json", 
	      success: function (data) { 
	    	  if(data.result==3){
	    		  	getlockcode();
	    	    	alert("请输入正确的图形验证码！");
	    	    }else{
	    	    	if(data.result==0){
	    	    		getlockcode();
		   		   		alert("短信已发送！");
		   	   		}else{
		   	   			getlockcode();
		      			alert("短信发送失败！");
		   	   		}
	    	    }
	      }, 
	      error: function (XMLHttpRequest, textStatus, errorThrown) { 
	    	 getlockcode();
	         alert("短信发送失败"); 
	         return false;
	      } 
	    });  
  }
      
      function changeMobile(){
    	  if($.trim($("#changemobile").val()) == ""){
  	        alert("手机号码不能为空！");
  	        return false;
  	    }
  	    if (!$("#changemobile").val().match(/^1[3,4,5,6,7,8,9]\d{9}$/)) { 
  	        alert("请正确填写手机号码！");
  	        return false;
  	    }
    	  if($.trim($("#usercode").val()) == ""){
  	        alert("验证码不能为空！");
  	        return false;
  	      }
    	  if($.trim($("#lockcode").val()) == ""){
  	        alert("图形验证码不能为空！");
  	        return false;
  	    }
    	  $.ajax({ 
    	      type: "post", 
    	      url: "/personalcenter/changemessage", 
    	      data: {mobile:$.trim($("#changemobile").val()),usercode:$.trim($("#usercode").val()),lockcode:$.trim($("#lockcode").val())},
    	      dataType: "json", 
    	      success: function (data) { 
    	   	   		if(data.result==0){
    	   	   		 	var changeMobile=$("#changemobile").val();
    	       	  		//$("#usermobile").html(changeMobile.replace(/(\d{3})\d{6}(\d{2})/,'$1******$2'));
    	       	  		$("#usermobile").val(changeMobile);
    	       	  		$("#usermobile").html(changeMobile.replace(/(\d{3})\d{6}(\d{2})/,'$1******$2'));
    	   	   			boxOut($('.out-changePhone'));
    	   	   		}else if(data.result==4){
    	   	   		 	getlockcode();
    	      			alert("请填写正确的图形验证码！");
    	   	   		}else if(data.result==1){
    	   	   		 	getlockcode();
    	      			alert("请填写正确手机号及验证码！");
    	   	   		}else if(data.result==2){
    	   	   			getlockcode();
    	   	   			alert("请先发送短信验证码！");
    	   	   		}else{
    		   	   		alert("请从正确的入口进行认证！");
    	   	   			window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe643cc1b34aa8f25&redirect_uri=http%3a%2f%2fa6.189young.com%2fpersonalcenter%2fcheckuser&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
    	   	   		}
    	      }, 
    	      error: function (XMLHttpRequest, textStatus, errorThrown) { 
    	         alert("修改失败"); 
    	         return false;
    	      } 
    	    });  
      }
      
  function commit(){
	    if($.trim($("#sel-school").val()) == ""){
	        alert("学校不能为空！");
	        return false;
	    }
	    if($.trim($("#sel-year").val()) == ""){
	        alert("入学年份不能为空！");
	        return false;
	    }
	  //向后台发送处理数据验证
		$.ajax({ 
	      type: "post", 
	      url: "/personalcenter/updateuser", 
	      data: {mobile:$.trim($("#usermobile").val()),school:$.trim($("#sel-school").val()),building:$.trim($("#sel-building").val()),schoolgrade:$.trim($("#sel-year").val()),schoolmajor:$.trim($("#usermajor").val()),name:$.trim($("#username").val())},
	      dataType: "json", 
	      success: function (data) { 
	   	   		if(data.result==0){
	   	   			//alert("恭喜你认证成功！");
	   		   		window.location.href="user_info.html";
	   	   		}else if(data.result==1){
	      			alert("请填写正确手机号及验证码！");
	   	   		}else if(data.result==2){
	   	   			alert("请先发送验证码！");
	   	   		}else{
		   	   		alert("请从正确的入口进行认证！");
	   	   			window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe643cc1b34aa8f25&redirect_uri=http%3a%2f%2fa6.189young.com%2fpersonalcenter%2fcheckuser&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
	   	   		}
	      }, 
	      error: function (XMLHttpRequest, textStatus, errorThrown) { 
	         alert("提交失败!"); 
	         return false;
	      } 
	    });  
  }
  function wait(){
	    var secs = 120; 
	    var wait = secs * 1000;
	    var i = "";
	    for (i = 1; i <= (wait / 1000); i++) {
	        window.setTimeout("doUpdate(" + i + ","+ wait +")", i * 1000);
	    }
	}

	function doUpdate(num,wait) {
	   if (num == (wait / 1000)) {
	   		 $("#button").removeAttr('disabled').text("获得验证码");
	   } else {
	       	var wut = (wait / 1000) - num;
	       	$("#button").text(wut+"秒").attr("disabled",true);
	   }
	}
    </script>

    <!--百度数据统计-->
    <script>var _hmt = _hmt || [];(function() {var hm = document.createElement("script");hm.src="https://hm.baidu.com/hm.js24866553cf6bdd25afcd437091f96447";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s);})();</script>

</body>
</html>
















